<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>关注的公司</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>

    <link rel="stylesheet" href="../js/libs/sui/sm.min.css">
    <link rel="stylesheet" href="../js/libs/sui/sm-extend.min.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <link rel="stylesheet" href="../less/main.css"/>

    <script type="text/javascript" src='../js/libs/jquery-3.1.0.min.js' charset='utf-8'></script>
    <script type="text/javascript">
        var Zepto = jQuery;
    </script>
    <script type="text/javascript" src='../js/libs/sui/sm.js' charset='utf-8'></script>
    <script type="text/javascript" src='../js/libs/sui/sm-extend.min.js' charset='utf-8'></script>
    <script type="text/javascript" src="../js/libs/juicer-min.js"></script>
    <script type="text/javascript" src="../js/libs/jquery.md5.js"></script>
    <script type="text/javascript" src="../js/api.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>
</head>
<body>
<!-- 这里是页面内容区 -->
<div class="page">
    <!-- 头部-->
    <div class="head-no-toolbar bg-self-green no-left-icon">
        <span class="icon iconfont c-white p-l" onclick="javascript:closeWin();">&#xe61f;</span>
        <span class="c-white t-center">关注的公司</span>
    </div>
    <div class="content pull-to-refresh-content" data-ptr-distance="20" style="top: 0;">
        <div class="pull-to-refresh-layer">
            <div class="preloader"></div>
            <div class="pull-to-refresh-arrow"></div>
        </div>
        <div class="list-block media-list list-job job-tool focus-company">
            <!--<ul>-->
            <!--<li>-->
            <!--<a load="public/pag../company-info.html" class="my-company-info" progress="false">-->
            <!--<div class="item-content">-->
            <!--<div class="item-media item-pb-0"><img src="http://gqianniu.alicdn.com/bao/upload..//tfsc../TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg" style='width: 3rem;'></div>-->
            <!--<div class="item-inner item-pb-0">-->
            <!--<div class="item-title-row">-->
            <!--<div class="item-title c-default">贵州安云科技有限公司</div>-->
            <!--</div>-->
            <!--<div class="item-subtitle">以软件、产品开发为主导，集产品研发研发</div>-->
            <!--</div>-->
            <!--</div>-->
            <!--</a>-->
            <!--</li>-->
            <!--<div class="item-foot1">-->
            <!--<a class="cancel"><i class="icon iconfont c-red">&#xe61c;</i>取消关注</a>-->
            <!--<div class="pull-right">-->
            <!--<a href="" class="my-company-info">查看详细 <span class="icon iconfont">&#xe620;</span></a>-->
            <!--</div>-->
            <!--</div>-->
            <!--</ul>-->
            <!--<ul>-->
            <!--<li>-->
            <!--<a load="public/pag../company-info.html" class="my-company-info" progress="false">-->
            <!--<div class="item-content">-->
            <!--<div class="item-media item-pb-0"><img src="http://gqianniu.alicdn.com/bao/upload..//tfsc../TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg" style='width: 3rem;'></div>-->
            <!--<div class="item-inner item-pb-0">-->
            <!--<div class="item-title-row">-->
            <!--<div class="item-title c-default">贵州安云科技有限公司</div>-->
            <!--</div>-->
            <!--<div class="item-subtitle">以软件、产品开发为主导，集产品研发研发</div>-->
            <!--</div>-->
            <!--</div>-->
            <!--</a>-->
            <!--</li>-->
            <!--<div class="item-foot1">-->
            <!--<a class="cancel"><i class="icon iconfont c-red">&#xe61c;</i>取消关注</a>-->
            <!--<div class="pull-right">-->
            <!--<a href="" class="my-company-info">查看详细 <span class="icon iconfont">&#xe620;</span></a>-->
            <!--</div>-->
            <!--</div>-->
            <!--</ul>-->
        </div>
    </div>
</div>
<script id="focus-company-tpl" type="text/template">
    {@each focusList as it,index}
    <ul>
        <li>
            <a data-focus-id="&{it.UNIT_ID}" class="my-company-info" progress="false">
                <div class="item-content">
                    <div class="item-media item-pb-0"><img src="&{it.PIC_PATH}" style='width: 3rem;'></div>
                    <div class="item-inner item-pb-0">
                        {@if (it.UNIT_NAME != null) && (it.UNIT_NAME != '')}
                        <div class="item-title-row">
                            <div class="item-title c-default">&{it.UNIT_NAME}</div>
                        </div>
                        {@/if}

                        {@if (it.REMARKS != null) && (it.REMARKS != '')}
                        <div class="item-subtitle">$${it.REMARKS}</div>
                        {@/if}
                    </div>
                </div>
            </a>
        </li>
        <div class="item-foot1">
            <a data-follow-id="&{it.FOLLOW_ID}" class="cancel"><i class="icon iconfont c-red">&#xe61c;</i>取消关注</a>
            <div class="pull-right">
                <a data-focus-id="&{it.UNIT_ID}" class="my-company-info">查看详细<span class="icon iconfont">&#xe620;</span></a>
            </div>
        </div>
    </ul>
    {@/each}
</script>
<script type="text/javascript">
    apiready = function () {
        juicer.set({
            'tag::operationOpen': '{@',
            'tag::operationClose': '}',
            'tag::interpolateOpen': '&{',
            'tag::interpolateClose': '}',
            'tag::noneencodeOpen': '$${',
            'tag::noneencodeClose': '}',
            'tag::commentOpen': '{#',
            'tag::commentClose': '}',
            'strip': false,
            'cache': false
        });

        // 查询数据 SQL
        var sql = "select s1.FOLLOW_ID,s1.STUDENT_ID,s1.STATE,s2.* from e_follow s1,e_cooperation_unit s2 where s1.STUDENT_ID='{0}' and s1.STATE=1 and s1.UNIT_ID=s2.UNIT_ID";

        //获取数据
        function getData(progressFlag) {
            var stuInfo = getLoginStudentInfo();
            //获取登陆用户id
            var studentId = stuInfo.STUDENT_ID;

            if (isObject(stuInfo) && isNumber(studentId)) {
                dbQuery(1, 10, sql.format(studentId), progressFlag, function (ret, err) {
                    if (isObject(ret) && (ret.statusCode == 0)) {
                        if (ret.result.length != 0) {
                            var focusData = {
                                focusList: ret.result,
                                url: getUrl()
                            };

                            // 添加默认图片
                            $.each(focusData.focusList, function (i, e) {
                                if (isEmpty(e.PIC_PATH)) {
                                    e.PIC_PATH = "../images/no_png.png";
                                } else {
                                    e.PIC_PATH = "{0}{1}".format(focusData.url, e.PIC_PATH);
                                }
                            });

                            $(".focus-company").html(juicer($("#focus-company-tpl").html(), focusData));
                        } else {
                            toast("暂无关注的公司");
                        }
                    }
                });
            }
        }

        //取消关注
        function cancelFocus(followId) {
            var sql = "UPDATE e_follow SET STATE=0 WHERE FOLLOW_ID='{0}'";
            dbExecute(sql.format(followId), false, function (ret, err) {
                if (isObject(ret) && ret.statusCode == 0) {
                    //刷新页面
                    location.reload();
                    toast("取消关注成功")
                }
            });
        }

        getData(true);

        //点击进入详细界面
        $(".focus-company").on("click", ".my-company-info", function () {
            var $this = $(this);
            var unitId = $this.data("focusId");
            openWin("company-info", "company-info.html", {
                unitId: unitId
            });
        });

        //取消关注按钮
        $(".focus-company").on("click", ".cancel", function () {
            var $this = $(this);
            var followId = $this.data("followId");
            cancelFocus(followId);
        });

        // 页数
        var mjyPage = 1;

        // 下拉刷新最新咨询
        $(document).on("refresh", ".pull-to-refresh-content", function () {
            var stuInfo = getLoginStudentInfo();
            //获取登陆用户id
            var studentId = stuInfo.STUDENT_ID;

            if (isObject(stuInfo) && isNumber(studentId)) {
                mjyPage++;

                // 获取就业单位
                dbQuery(mjyPage, 10, sql.format(studentId), false, function (ret, err) {
                    if (isObject(ret) && (ret.statusCode == 0)) {
                        var focusData = {
                            focusList: ret.result,
                            url: getUrl()
                        };

                        if (focusData.focusList.length > 0) {
                            // 添加默认图片
                            $.each(focusData.focusList, function (i, e) {
                                if (isEmpty(e.PIC_PATH)) {
                                    e.PIC_PATH = "../images/no_png.png";
                                } else {
                                    e.PIC_PATH = "{0}{1}".format(focusData.url, e.PIC_PATH);
                                }
                            });

                            $(".focus-company").prepend(juicer($("#focus-company-tpl").html(), focusData));
                        } else {
                            toast("已加载完毕");

                            mjyPage--;
                        }
                    }

                    $.pullToRefreshDone(".pull-to-refresh-content");
                });
            }
        });

        //监听关注事件
        api.addEventListener({name: "companyEvent"}, function (ret, err) {
            //刷新页面
            location.reload();
        });
    };
</script>
<script>$.init();</script>
</body>
</html>
